home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / PROBLEMS / BENCHMARK / BUBBLESORT / bubbletest / gawk_l / source < prev    next >
Text File  |  1992-05-13  |  660b  |  37 lines

  1.  
  2. function bubblesort(a,len \
  3.                     ,flag,count,temp)
  4.   {
  5.   flag=1;
  6.   while (flag)
  7.      {
  8.      flag=0;
  9.      for (count=0;count<len-1;count=count+1)
  10.         if (a[count]>a[count+1])
  11.            {
  12.            temp=a[count]
  13.            a[count]=a[count+1]
  14.            a[count+1]=temp
  15.            flag=1;
  16.            } 
  17.      }
  18.   }  
  19.  
  20. BEGIN {
  21. # pseudo ramdom
  22.  pseudoramdom=123456;
  23.  for (count=0;count<1000;count=count+1)
  24.     {
  25.     pseudoramdom=(pseudoramdom + 234567) % 567 + 345
  26.     a[count]=pseudoramdom;
  27.     print(a[count])
  28.     }   
  29.  
  30.  system("time")
  31.  bubblesort(a,1000)
  32.  system("time") 
  33.  
  34.  for (count=0;count<1000;count=count+1)
  35.     print(a[count])
  36.  }   
  37.